<!--设置模块唯一ID-->
<div>
<!--标题、面包屑-->
<section class="content-header">
    <h1>
        人事发文
        <small>消息</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li >消息</li>
        <li class="active">人事发文</li>
    </ol>
</section>
<!--列表-->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="btn-group pull-left" data-type="actionBar">
                        <button type="button" class="btn btn-default" data-action="remove"><i class="fa fa-remove"></i> 删除</button>
                    </div>
                    <div class=" pull-right" data-type="columnControl">
                    </div>
                    <div class=" pull-right " data-type="searchControl">
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="box-body">
                    <table class="table table-bordered table-striped table-hover"></table>
                </div>
            </div>
        </div>
    </div>
</section>

<script>
    USEN(function () {
//        console.log(this);
        //模块ID(全系统唯一)
        var id = "#common_message";

        //定义页面变量
        var $el = $(id);
        var $actionBar = $el.find("[data-type=actionBar]");
        var tableId = id + " table.table";
        var $table = $(tableId);
        var myTable;

        this.initPermission(id);

        //定义增\删\改 方法
        var editor = {
            remove: function (data) {
                USEN.modal({
                    title: "提示",
                    content: "是否删除这条数据?",
                    submitTxt: "删除",
                    submitCb: function ($el) {
                        $.ajax({
                            url: "./simdata/common_remove_action.json",
                            data: data,
                            success: function (result) {
                                USEN.notifyAlert({
                                    title: "提示:",
                                    content: '删除成功.'
                                });
                                $el.modal("hide");
                                if (myTable) myTable.ajax.reload();
                            }
                        })
                    }
                })
            }
        };


        // 绑定列表编辑按钮事件
        $actionBar.find("[data-action]").on("click", function () {
            var action = $(this).data("action");
            var $selected = $table.find('tr.selected');
            switch (action) {
                case "remove" :
                    if ($selected.length > 0) {
                        editor.remove(myTable.row($selected).data());
                    } else {
                        //提示"请选中要修改的行"
                        USEN.modal({
                            title: "提示",
                            content: "请选中要修改的行.",
                            cancelBtn: true,
                            cancelTxt: "关闭"
                        })
                    }
                    break;
            }
        });

        //初始化datatable数据列表
        myTable = new USEN.Datatable({
            "scrollX":false,
            //设置ID
            "id": tableId,
            //设置列控制模块容器
            "columnControl": id + " [data-type=columnControl]",
            //设置搜索模块容器
            "searchControl": id + " [data-type=searchControl]",
            //每行"操作"自定义action按钮回调
            onItemAction: function ($tr, action) {
                switch (action) {
                    case "remove" :
                        editor.remove(this.row($tr).data());
                        break;
                }
            },
            //配置服务
            "ajax": {
                url:"./simdata/common_table_ation.json",
                data:{
                    anyKey:'anyValue'
                }
            },
            //对某些列设置默认排序
            "order": [[ 2, 'desc' ]],
            //设置可以拖动区间(不可拖动的列数)
            colReorder: {
                fixedColumnsLeft: 2,
                fixedColumnsRight: 0
            },
            //列设置
            "columns": [
                {
                    data: null,
                    defaultContent: '',
                    className: 'select-checkbox',
                    orderable: false, searchable: false,
                    width: "30px"
                },
                { "title": "操作", "data": null, orderable: false, searchable: false, width: '200px', render: function (data, type, full, meta) {
                    return '<button data-item-action="remove" class="btn btn-danger">删除</button>'
                }},
                { "title": "业务",  "data": "p1"},
                { "title": "内容", "data": "p2"},
                { "title": "操作人", "data": "p3"},
                { "title": "创建日期", "data": "p4"}
            ]
        })
    });
</script>
</div>